#!/bin/bash

PWD=`pwd`

function print_usage()
{
    echo "usage:${0} debug | release | clean"
}

function create_dir()
{
    cd ${PWD}

    if [ -d "${PWD}/build" ]; then
        echo "directory ${PWD}/build is exist"
    else
        mkdir ${PWD}/build
    fi
}

function build_release()
{
    echo "---building release version---"
    cd ${PWD}/build
    cmake ..
    make -j6
}

function build_debug()
{
    echo "---building debug version---"
    cd ${PWD}/build
    cmake .. -DCMAKE_BUILD_TYPE=Debug
    make -j6
}

function clean()
{
    echo "---cleaning---"
    rm -rf ${PWD}/build
}

if [ ${#} -lt 1 ]; 
then
    print_usage
    exit 1
else
    if [ ${1} == "debug" ];
    then
        create_dir
        build_debug
    elif [ ${1} == "release" ];
    then
        create_dir
        build_release
    elif [ ${1} == "clean" ];
    then
        clean
    else
        echo "not support arg:${1}"
        print_usage
    fi
fi
